unit uMainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Sockets, StdCtrls, AppEvnts, uGameClient, uGlobal;

type
  TMainForm = class(TForm)
    TcpClient1: TTcpClient;
    Memo1: TMemo;
    ApplicationEvents1: TApplicationEvents;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    FClients: TList;
    procedure DebugLog(var message: TMessage); message WM_DEBUGLOG;
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

uses
  uProtoBuf;
{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
var
  cli: TGameClient;
begin
  G_DebugWindow := Handle;
  FClients := TList.Create;
  cli := TGameClient.Create;
  cli.Init('113.107.71.217', 5000);
  FClients.Add(cli);
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
  FClients.Free;
end;

procedure TMainForm.ApplicationEvents1Idle(Sender: TObject;
  var Done: Boolean);
var
  tick: DWORD;
  i: Integer;
begin
  tick := GetTickCount;
  for i := 0 to FClients.Count - 1 do
  begin
    with TGameClient(FClients[i]) do
    begin
      Run(tick);
    end;
  end;
end;

procedure TMainForm.DebugLog(var message: TMessage);
begin
  Memo1.Lines.Add(PChar(message.WParam));
  FreeMem(PChar(message.WParam));
end;

procedure TMainForm.Button1Click(Sender: TObject);
var
  s: TByteStream;
begin
  s := TByteStream.Create;
  s.WriteUInt(100);
  s.Position := 0;
  ShowMessage(IntTostr(s.ReadUInt));
end;

end.
